<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>拖放事件</title>
  <style>
    #dragTarget, #dropTarget {
      display: inline-block;
      margin: 0 10px;
      width: 50px;
      height: 50px;
    }
    #dragTarget {
      background-color: red;
    }
    #dropTarget {
      background-color: blue;
    }
  </style>
</head>
<body>
  <div id="dragTarget"></div>
  <div id="dropTarget"></div>

  <script>
    const dragTarget = document.querySelector('#dragTarget');
    const dropTarget = document.querySelector('#dropTarget');

    dragTarget.addEventListener('dragstart', ev => {
      console.log('dragstart');
    });
    dragTarget.addEventListener('drag', ev => {
      console.log('drag');
    });
    dragTarget.addEventListener('dragend', ev => {
      console.log('dragend');
    });

    dropTarget.addEventListener('dragenter', ev => {
      ev.preventDefault();
      console.log('dragenter');
    });
    dropTarget.addEventListener('dragover', ev => {
      ev.preventDefault();
      console.log('dragover');
    });
    dropTarget.addEventListener('dragleave', ev => {
      console.log('dragleave');
    });
    dropTarget.addEventListener('drop', ev => {
      console.log('drop');
    });
  </script>
</body>
</html>